package com.huanwei.cc.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.huanwei.cc.R;
import com.huanwei.cc.base.BaseActivity;
import com.huanwei.cc.bean.PassWordBean;

/**
 * Created by ADM on 2017/12/4.
 * 修改密碼
 */

public class MePasswordActivity extends BaseActivity implements View.OnClickListener {

    private ImageView me_set_path;
    private TextView me_complete;
    private EditText me_password_Oldcipher;
    private EditText me_password_newcipher;
    private EditText me_password_confirm;
    private String mS2;
    private String mS;
    private String mS1;
    private PassWordBean mBean2;

    @Override
    public int setLayoutId() {
        return R.layout.me_password_activity;
    }

    @Override
    public void initViewsAndEvents() {
        me_set_path = (ImageView) findViewById(R.id.me_set_path);
        me_set_path.setOnClickListener(this);
        me_complete = (TextView) findViewById(R.id.me_complete);
        me_complete.setOnClickListener(this);


        me_password_Oldcipher = (EditText) findViewById(R.id.me_password_Oldcipher);
        me_password_newcipher = (EditText) findViewById(R.id.me_password_newcipher);
        me_password_confirm = (EditText) findViewById(R.id.me_password_confirm);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.me_set_path:
                finish();
                break;
            case R.id.me_complete:
                logic();
                break;


        }
    }

    private void logic() {
        mS2 = me_password_Oldcipher.getText().toString();
        mS = me_password_newcipher.getText().toString();
        mS1 = me_password_confirm.getText().toString();
        if (mS2.isEmpty() && mS.isEmpty() && mS1.isEmpty()) {
            Toast.makeText(getApplicationContext(), "您有数据没填写", Toast.LENGTH_LONG).show();
        }
        if (mS.equals(mS1)) {
            PasswordAccess();
            Toast.makeText(getApplicationContext(), "修改成功！", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(), "新旧密码不一致", Toast.LENGTH_LONG).show();
        }
    }

    private void PasswordAccess() {
        finish();
//        API.ModifyPassword(mS2, mS1, new Okhttp.Objectcallback() {
//            @Override
//            public void onsuccess(String st) {
//                Log.e("MePasswordActivity",st);
//                mBean2 = JSONUtils.parseJSON(st, PassWordBean.class);
//                if (mBean2.getType() == 1) {
//                    Toast.makeText(getApplicationContext(), mBean2.getMessage() + "", Toast.LENGTH_SHORT).show();
//                }
//
//            }
//            @Override
//            public void onFalia(int code, String errst) {
//
//            }
//        });
    }
}
